home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / BracketCountDA-c / window.c < prev   
Encoding:
Text File  |  1994-12-04  |  4.9 KB  |  231 lines  |  [TEXT/KAHL]

  1. sBegin    =    -1;
  2. long                 sEnd    =    -1;
  3.  
  4. TEHandle            myTE;
  5.  
  6. FontInfo     fInfo;
  7.  
  8. long abs(i)
  9. long i;
  10. {
  11.     if (i<0) return(-i);
  12.     else return(i);
  13. }
  14.  
  15.  
  16. int         firstLine,lastLine,line,MaxLines;
  17.  
  18. void doUpdate()
  19. {
  20.     struct sentence *where;
  21.     GrafPtr        savePort;
  22.     Point        place;
  23.     
  24.     GetPort(&savePort);
  25.     SetPort(wp);
  26.     
  27.     /*
  28.         starting and stopping places on the screen
  29.     */
  30.     
  31.     firstLine = GetCtlValue(vScroll);
  32.     lastLine = (wp->portRect.bottom - wp->portRect.top)/10 + firstLine;
  33.     MaxLines = GetCtlMax(vScroll);
  34.     if (MaxLines < lastLine)
  35.         lastLine = MaxLines;
  36.         
  37.     Scroll_Bits();
  38.     
  39.     place.h = 40;
  40.     place.v = 20;
  41.     
  42.     BeginUpdate(wp);
  43.     DrawControls(wp);
  44.     for (line = 0,where = &begin; line < lastLine; line++, where = where->next)
  45.     {
  46.         if (line >= firstLine)
  47.         {
  48.             MoveTo(7,place.v);
  49.             DrawChar(where->paren);
  50.             MoveTo(14,place.v);
  51.             DrawChar(where->square);
  52.             MoveTo(21,place.v);
  53.             DrawChar(where->curly);
  54.             MoveTo(28,place.v);
  55.             DrawChar(where->comment);
  56.             
  57.             MoveTo(place.h,place.v);
  58.             DrawString(where->what);
  59.             place.v +=10;
  60.             }
  61.         }
  62.     EndUpdate(wp);
  63.     
  64.     SetPort(savePort);
  65. }
  66.  
  67. doActivate(activate)
  68. Boolean activate;
  69. {
  70.     GrafPtr    savePort;
  71.     
  72.     GetPort(&savePort);
  73.     SetPort(wp);
  74.     
  75.     if ( activate ) ShowControl( vScroll );
  76.     else HideControl( vScroll );
  77.         
  78.     DrawControls(wp);
  79.     SetPort(savePort);
  80. }
  81.  
  82. Scroll_Bits()
  83. {
  84.     int            oldTop;
  85.     RgnHandle    tmpRgn, saveRgn;
  86.     long        dv;
  87.     Rect        r;
  88.     
  89.     oldTop = curTop;
  90.     curTop = GetCtlValue( vScroll );
  91.     dv = (long)10 * (oldTop-curTop);
  92.  
  93.     r = wp->portRect;
  94.     r.top += 2 + 10;
  95.     r.right -= 16;
  96.     r.bottom = r.top + lastLine*10;
  97.     tmpRgn = NewRgn();
  98.     saveRgn = NewRgn();
  99.     CopyRgn(wp->clipRgn, saveRgn);
  100.     if (dv) 
  101.     {
  102.         if (abs(dv) >= (long)lastLine * 10) 
  103.         {
  104.             EraseRect( &r );
  105.             RectRgn( tmpRgn, &r );
  106.         }
  107.         else 
  108.             {
  109.                 saveRgn = NewRgn();
  110.                 CopyRgn(wp->clipRgn, saveRgn);
  111.                 ClipRect(&r);
  112.                 ScrollRect( &r, 0, dv, tmpRgn );
  113.                 SetClip(saveRgn);
  114.                 DisposeRgn(saveRgn);
  115.         }
  116.         InvalRgn( tmpRgn );
  117.     }
  118.     DisposeRgn( tmpRgn );
  119. }
  120.  
  121. int scrollCode;
  122. int scrollAmt;
  123.  
  124. pascal void ScrollProc(theControl, theCode)
  125. ControlHandle    theControl;
  126. int                theCode;
  127. {
  128.     int locVal;
  129.     GrafPtr theWindow;
  130.     
  131.     SetUpA4();
  132.     if (theCode==scrollCode) 
  133.     {
  134.         locVal = GetCtlValue(theControl);
  135.         SetCtlValue( theControl, locVal+scrollAmt );
  136.         doUpdate();
  137.     }
  138.     RestoreA4();
  139. }
  140.  
  141. doScrollControl(p)
  142. Point p;
  143. {
  144.     GrafPtr savePort;
  145.     int code,v;
  146.     ControlHandle theControl;
  147.     
  148.     RememberA4();
  149.  
  150.     GetPort( &savePort );
  151.     SetPort( wp );
  152.  
  153.     GlobalToLocal(&p);
  154.     switch ( code = FindControl(p, wp, &theControl) ) 
  155.     {
  156.         case inUpButton:     
  157.             scrollAmt = -1;         
  158.         break;
  159.         
  160.         case inDownButton:     
  161.             scrollAmt = 1;             
  162.         break;
  163.         
  164.         case inPageUp:        
  165.             scrollAmt = (wp->portRect.top - wp->portRect.bottom)/10+1;     
  166.             break;
  167.         case inPageDown:
  168.             scrollAmt = (wp->portRect.bottom - wp->portRect.top)/10-1;
  169.         break;
  170.         
  171.         default: 
  172.         break;
  173.     }
  174.     if (theControl==vScroll) 
  175.     {
  176.         switch (code) 
  177.         {
  178.             case inUpButton:
  179.             case inDownButton:
  180.             case inPageUp:
  181.             case inPageDown:
  182.                 scrollCode = code;
  183.                 if (TrackControl(vScroll, p, &ScrollProc)) ;
  184.             break;
  185.             
  186.             case inThumb:
  187.                 if (TrackControl(theControl, p, 0L )) ;
  188.                 doUpdate();
  189.             break;
  190.             
  191.             default: 
  192.             break;
  193.         }
  194.     }
  195.     SetPort( savePort );
  196. }
  197.  
  198.  
  199. /* Create_Window - create my test window */
  200.  
  201. #define WINDOWWIDTH     480
  202. #define WINDOWHEIGHT     276
  203. #define WINDOWTOP        40
  204. #define WINDOWLEFT        10
  205. #define WINDOWBOTTOM    WINDOWTOP + WINDOWHEIGHT
  206. #define WINDOWRIGHT        WINDOWLEFT + WINDOWWIDTH
  207. #define SBARWIDTH         16
  208. #define SBARLEFT        WINDOWWIDTH - SBARWIDTH + 1
  209. #define SBARRIGHT        WINDOWWIDTH + 1
  210. #define SBARBOTTOM        WINDOWHEIGHT - SBARWIDTH + 2
  211.  
  212.  
  213.  
  214. Create_Window()
  215. {
  216.     GrafPtr    savePort;
  217.     static     Rect    bounds = {     WINDOWTOP, WINDOWLEFT, 
  218.                                 WINDOWBOTTOM, WINDOWRIGHT },
  219.                     scrollBounds = { -1, SBARLEFT,
  220.                                      SBARBOTTOM, SBARRIGHT };
  221.                     
  222.     GetPort(&savePort);
  223.     wp = NewWindow( 0L, &bounds, "", FALSE, 8, 0L, TRUE, 0L );
  224.     if (!wp)
  225.             Hell ("\pCreate_Window","\pwindow not assigned");
  226.     
  227.     /* IMPORTANT - set the windowkind to the dCtlRefNum */
  228.     ((WindowPeek)wp)->windowKind = dce->dCtlRefNum;
  229.     dce->dCtlWindow = wp;                            /* courtesy of TLL */
  230.  
  231.     /* set up the window's font and line heig